//
//  CommentViewController.m
//  YJRenter
//
//  Created by 文彬 on 2018/7/8.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "CommentViewController.h"
#import "WBScrollSelectView.h"
#import "OrderInfoTableViewCell.h"
#import "OrderTimeTableViewCell.h"
#import "CommentOperationTableViewCell.h"
#import "MakeCommentViewController.h"
#import "OperationTableViewCell.h"
#import "RoomCommentsViewController.h"

@interface CommentViewController ()<UITableViewDelegate,
    UITableViewDataSource,
    WBScrollSelectDelegate>
{
    int commentType; //0:未评价 1：已评价
}

@property (strong, nonatomic) WBScrollSelectView *scrllSelectView;
@property (strong, nonatomic) UITableView *listTableView;

@end

@implementation CommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"评论";
    
    [self initPageControl];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark 页面相关
- (void)initPageControl{
    
    [self.view addSubview:self.scrllSelectView];
    
    [self.view addSubview:self.listTableView];
    [self.listTableView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@(self.scrllSelectView.frame.size.height+1));
        make.bottom.equalTo(@0);
    }];
    
}

#pragma mark WBScrollSelectDelegate
- (void)ScrollSelectDidCickWith:(int)num{
    
    commentType = num;
    [self.listTableView reloadData];
}
#pragma mark UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 10;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        return 40;
    }
    else if(indexPath.row==1)
    {
        return 100;
    }
    return 45;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        
        OrderTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderTimeTableViewCell" forIndexPath:indexPath];
        return cell;
    }
    else if(indexPath.row==1){
        OrderInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderInfoTableViewCell" forIndexPath:indexPath];
        [cell.imgView sd_setImageWithURL:[NSURL URLWithString:@"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4036889747,3526425271&fm=27&gp=0.jpg"] placeholderImage:nil];
         return cell;
    }
    
    if (commentType==0) {
    
        CommentOperationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommentOperationTableViewCell" forIndexPath:indexPath];
        return cell;
        
    }
    
    WeakObj(self)
    OperationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OperationTableViewCell" forIndexPath:indexPath];
    [cell.viewBtn buttonClick:^{
        
        RoomCommentsViewController *commentController = [[RoomCommentsViewController alloc]init];
        [selfWeak.navigationController pushViewController:commentController animated:YES];
    }];
    [cell.commentBtn buttonClick:^{
        MakeCommentViewController *makeCommentController = [[MakeCommentViewController alloc]init];
        [selfWeak.navigationController pushViewController:makeCommentController animated:YES];
    }];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row==2&&commentType==0) {
        MakeCommentViewController *makeCommentController = [[MakeCommentViewController alloc]init];
        [self.navigationController pushViewController:makeCommentController animated:YES];
    }
}

#pragma mark getter
- (WBScrollSelectView*)scrllSelectView{
    if (_scrllSelectView==nil) {
        _scrllSelectView = [[WBScrollSelectView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40) titles:@[@"未评价",@"已评价"]];
        _scrllSelectView.delegate = self;
        _scrllSelectView.LineWith = 0;
    }
    return _scrllSelectView;
}

- (UITableView*)listTableView{
    if (_listTableView==nil) {
        _listTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        _listTableView.sectionFooterHeight = 0;
        _listTableView.separatorColor = kLineColor;
        _listTableView.backgroundColor = [UIColor clearColor];
        [_listTableView registerNib:[UINib nibWithNibName:@"OrderInfoTableViewCell" bundle:nil] forCellReuseIdentifier:@"OrderInfoTableViewCell"];
        [_listTableView registerNib:[UINib nibWithNibName:@"OrderTimeTableViewCell" bundle:nil] forCellReuseIdentifier:@"OrderTimeTableViewCell"];
         [_listTableView registerNib:[UINib nibWithNibName:@"CommentOperationTableViewCell" bundle:nil] forCellReuseIdentifier:@"CommentOperationTableViewCell"];
        [_listTableView registerNib:[UINib nibWithNibName:@"OperationTableViewCell" bundle:nil] forCellReuseIdentifier:@"OperationTableViewCell"];
        
        
        
        
    }
    
    return _listTableView;
}



@end
